from autoaugment import ImageNetPolicy
import PIL
import pandas as pd
import getopt
import sys
import os

# label_data = pd.read_csv('train/train.csv')
path = 'G:/code/CharSample_Gen_Deal/'


def label_choose(label):
    allImagePath = os.listdir(path + str(label) + '/')

    allImagePath = list(map(lambda image: path + str(label) + '/' + image, allImagePath))
    return allImagePath


def autoaugment(label):
    names = label_choose(label)
    path = 'G:/code/imagesAutoaugment/'
    print("label: " + str(label))
    for i in range(len(names)):
        if not os.path.exists(path + str(label)):
            os.makedirs(path + str(label))
        else:
            pass
        try:
            policy = ImageNetPolicy()
            img = policy(PIL.Image.open(names[i]))
            img.save(path + str(label) + '/' + str(i) + '.jpg')
        except:
            pass


if __name__ == '__main__':
    list(map(lambda label: autoaugment(label), [x for x in range(200)]))
